<template>
    <div>
        <div class="section-wrap">
            <div class="form-section">
                <div class="form-item form-item-style1">
                    <div class="label-title">
                        <label>上级单位</label>
                    </div>
                    <div class="equipment-right-select"
                         @click="selectType">
                        <span>{{checkcompany.Name?checkcompany.Name:'请选择'}}</span>
                        <i class="iconfont icon-jinru rightmsg"></i>
                    </div>
                </div>
                <div v-show="checkcompany.Category == 1">
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>分包商名称</label>
                            <i class="iconfont icon-required"></i>
                        </div>
                        <div>
                            <input type="text"
                                   v-model="formData.conname"
                                   placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>企业资质证号</label>
                            <i class="iconfont icon-required"></i>
                        </div>
                        <div>
                            <input type="text"
                                   v-model="formData.Certification"
                                   placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>现场负责人</label>
                            <i class="iconfont icon-required"></i>
                        </div>
                        <div>
                            <input type="text"
                                   v-model="formData.enrolfund"
                                   placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>联系电话</label>
                            <i class="iconfont icon-required"></i>
                        </div>
                        <div>
                            <input type="text"
                                   v-model="formData.tel"
                                   placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>入厂时间</label>
                            <i class="iconfont icon-required"></i>
                        </div>
                        <group>
                            <datetime v-model="formData.SubOverTime"></datetime>
                        </group>
                    </div>
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>离场时间</label>
                            <i class="iconfont icon-required"></i>
                        </div>
                        <group>
                            <datetime v-model="formData.ContractDate"></datetime>
                        </group>
                    </div>
                </div>
                <div v-show="checkcompany.Category == 2">
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>班组名称 </label>
                            <i class="iconfont icon-required"></i>
                        </div>
                        <div>
                            <input type="text"
                                   v-model="formData1.conname"
                                   placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>班组长</label>
                            <i class="iconfont icon-required"></i>
                        </div>
                        <div>
                            <input type="text"
                                   v-model="formData1.enrolfund"
                                   placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>联系电话</label>
                            <i class="iconfont icon-required"></i>
                        </div>
                        <div>
                            <input type="text"
                                   v-model="formData1.tel"
                                   placeholder="请输入">
                        </div>
                    </div>
                </div>
                <div class="btns">
                    <button @click="submit">提交</button>
                </div>
            </div>
        </div>
        <myMenu></myMenu>
    </div>
</template>
<script>
import myMenu from '@/commonComponents/menu'
export default {
    data () {
        return {
            formData: {
                conname: '', // 分包商名称 或 班组名称
                Certification: '', // 企业资质证号
                enrolfund: '', // 现场负责人 或 班组长
                tel: '', // 联系电话
                SubOverTime: '', // 入场时间
                ContractDate: '' // 离场时间
            },
            formData1: {
                conname: '', //  班组名称
                enrolfund: '', // 班组长
                tel: '' // 联系电话
            },
            userInfo: {},
            checkcompany: {}
        }
    },
    components: {
        myMenu
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
        this.checkcompany = this.$store.state.checkcompany && JSON.stringify(this.$store.state.checkcompany) !== '{}' ? JSON.parse(JSON.stringify(this.$store.state.checkcompany)) : {
            Name: this.userInfo.deptname,
            Id: this.userInfo.deptid,
            Category: this.userInfo.departsir
        }
        this.checkcompany.Category = this.checkcompany.Category || this.userInfo.departsir
    },
    beforeDestroy () {
    },
    methods: {
        selectType () {
            this.$router.push({
                path: '/testing/lookcompany',
                query: {
                    business: 'GetFbDeptByDeptId'
                }
            })
        },
        submit () {
            let formData
            if (this.checkcompany.Category == 1) {
                if (!this.formData.conname) {
                    this.$vux.toast.text('请输入分包商名称')
                    return false
                } else if (!this.formData.Certification) {
                    this.$vux.toast.text('请输入企业资质证号')
                    return false
                } else if (!this.formData.enrolfund) {
                    this.$vux.toast.text('请输入现场负责人')
                    return false
                } else if (!(/^1[3456789]\d{9}$/.test(this.formData.tel))) {
                    this.$vux.toast.text('请输入正确的手机号')
                    return false
                } else if (!this.formData.SubOverTime) {
                    this.$vux.toast.text('请选择入场时间')
                    return false
                } else if (!this.formData.ContractDate) {
                    this.$vux.toast.text('请选择离场时间')
                    return false
                }
                formData = this.formData
            } else {
                if (!this.formData1.conname) {
                    this.$vux.toast.text('请输入班组名称')
                    return false
                } else if (!this.formData1.enrolfund) {
                    this.$vux.toast.text('请输入班组长')
                    return false
                } else if (!(/^1[3456789]\d{9}$/.test(this.formData1.tel))) {
                    this.$vux.toast.text('请输入正确的手机号')
                    return false
                }
                formData = this.formData1
            }
            formData.type = this.checkcompany.Category
            formData.parentid = this.checkcompany.Id
            let param = {
                'allowPaging': true,
                'business': 'SaveFbInfo',
                'data': {
                    ...formData
                },
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': this.tokenId,
                'userId': this.userId
            }
            this.$axiosAjax.getConfigJson(param).then(
                (res) => {
                    if (res.data.code == 0) {
                        this.$vux.toast.text('提交成功')
                        this.$router.back()
                    } else {
                        this.$vux.toast.text(res.data.info)
                    }
                }
            )
        }
    }
}
</script>
<style lang="less" scoped>
.vux-x-switch.weui-cell_switch {
    width: 100%;
}
.right-select {
    font-size: 14px;
    color: #999;
    padding-right: 0px;
    height: 20px;
    overflow: hidden;
    width: 180px;
    position: relative;
    padding-right: 0px;
    line-height: 20px;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.icon-jinru {
    color: #c8c8cd;
}
.right-select {
    font-size: 14px;
    color: #999;
}
.lookmsg {
    color: #2269ff;
}
</style>
<style scoped>
.telVerify {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
}
.bg {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    background: rgba(0, 0, 0, 0.3);
}
.content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
    width: 300px;
    padding: 20px;
    background: #fff;
    border-radius: 4px;
}
.content .item {
    color: #666;
    font-size: 16px;
    display: flex;
    padding: 15px 0;
}
.content label {
    width: 60px;
    height: 26px;
    line-height: 26px;
}
.content input {
    width: 100%;
    height: 26px;
    color: #666;
    font-size: 14px;
    border-bottom: 1px solid #ccc;
}
.content .item > div {
    position: relative;
    flex: 1;
}
.content .item button {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 70px;
    height: 30px;
    background: #419df7;
    color: #fff;
    padding: 0 5px;
    border-radius: 2px;
}
.content .item button[disabled] {
    background: #ccc;
}
.submit {
    display: block;
    width: 100%;
    height: 35px;
    margin: 0 auto;
    border-radius: 4px;
    background: #419df7;
    color: #fff;
    margin-top: 10px;
}
</style>
